package com.lanou.pianke.search.service.impl;

import com.lanou.pianke.search.EntityRepository.PreplyRepository;
import com.lanou.pianke.search.entity.Preply;
import com.lanou.pianke.search.service.PreplyService;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


@Service
public class PreplyServiceImpl implements PreplyService {

    @Autowired
    private PreplyRepository preplyRepository;

    @Override
    public List<Preply> searchByPreplyContent(String searchContent) {
        QueryStringQueryBuilder builder = new QueryStringQueryBuilder(searchContent);
        Iterable<Preply> search = preplyRepository.search(builder);
        Iterator<Preply> iterator = search.iterator();
        List<Preply> preplyList = new ArrayList<>();
        while (iterator.hasNext()){
            preplyList.add(iterator.next());
        }
        return preplyList;
    }
}
